ThingNN : Multi object detection and classify
The thingnn
module provides thing detection and recognition function.
User can use the following code to import the thingnn
module.
var thingnn = require('thingnn');
Support
The following shows thingnn
module APIs available for each permissions.
User Mode | Privilege Mode | |
---|---|---|
thingnn.detect | ● | ● |
thingnn.identify | ● | ● |
thingnn Object
thingnn.detect(videoBuf, attribute)
videoBuf
{Buffer} Video buffer.attribute
{Object} Video attribute.- Returns: {Array} Thing info objects array which detectd.
Detect thing infos in given video buffer.
The video attribute attribute
object contains the following members:
width
{Integer} Video width.height
{Integer} Video height.pixelFormat
{Integer} Pixel format.
pixelFormat
is a integer, can be:
Value | Description |
---|---|
thingnn.PIX_FMT_BGR24 | BGR24 pixel format. |
thingnn.PIX_FMT_RGB2BGR24 | RGB24 to BGR24 pixel format. |
thingnn.PIX_FMT_GRAY2BGR24 | Grayscale to BGR24 pixel format. |
thingnn.PIX_FMT_RGBA2BGR24 | RGBA to BGR24 pixel format. |
The returned thing info object contains the following members:
className
{String} Thing class name.prob
{Number} Probability0.0 ~ 1.0
.x0
{Integer} x position of upper left corner.y0
{Integer} y position of upper left corner.x1
{Integer} x position of lower right corner.y1
{Integer} y position of lower right corner.
className
is a string, can be: background
, aeroplane
, bicycle
, bird
, boat
, bottle
, bus
, car
, cat
, chair
, cow
, diningtable
, dog
, horse
, motorbike
, person
, pottedplant
, sheep
, sofa
, train
, tvmonitor
.
thingnn.identify(videoBuf, attribute, thingInfo)
videoBuf
{Buffer} Video buffer.attribute
{Object} Video attribute.thingInfo
{Object} Thing info object.- Returns: {String} Thing name.
Identify the name of given thing info.
Example
This example show how to detect and identify thing.
var MediaDecoder = require('mediadecoder');
var iosched = require('iosched');
var thingnn = require('thingnn');
var netcam = new MediaDecoder().open('rtsp://admin:admin@10.4.0.12');
netcam.destVideoFormat({width: 640, height: 360, fps: 1, pixelFormat: MediaDecoder.PIX_FMT_BGR24, noDrop: false, disable: false});
netcam.destAudioFormat({disable: true});
netcam.previewFormat({enable: true, fb: 0, fps: 25, fullscreen: false});
var ol = netcam.overlay();
var quited = false;
netcam.on('video', (video) => {
var buf = new Buffer(video.arrayBuffer);
var thingInfo = thingnn.detect(buf, {width: 640, height: 360, pixelFormat: thingnn.PIX_FMT_BGR24});
ol.clear();
if (thingInfo.length) {
ol.font(ol.F8X12);
for (var i = 0; i < thingInfo.length; i++) {
var thingName = thingnn.identify(buf, {width: 640, height: 360, pixelFormat: thingnn.PIX_FMT_BGR24}, thingInfo[i]);
ol.text(thingInfo[i].x0, thingInfo[i].y0, thingInfo[i].className, MediaDecoder.C_RED);
ol.text(thingInfo[i].x0, thingInfo[i].y0 + 20, thingName, MediaDecoder.C_RED);
ol.rect(thingInfo[i].x0, thingInfo[i].y0, thingInfo[i].x1, thingInfo[i].y1, MediaDecoder.C_RED, 2, 0, false);
}
}
});
netcam.on('eof', () => {
quited = true;
});
netcam.start();
while (!quited) {
iosched.poll(); // Event poll.
}
netcam.close();